
// 判断是否为通用名称，要求为(汉字,字母,数字,_,-,.)等组成
export function isCommonName(value) {
    const reg = /^[a-zA-Z0-9\u4e00-\u9fa5\\._-]*$/i
    return reg.test(value)
};

// 判断是否为数字,包括小数，整数
export function isNumber(value) {
    return !isNaN(parseFloat(value)) && isFinite(value);
};

// 判断是否为整数
export function isInteger(value) {
    return /^\d*$/i.test( value );
};

// 判断是否为IPv4地址,用于单个具有实际意义的IP地址
export function isIPv4(value) {
    const reg = /^([1-9]|[1-9][0-9]|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.([1-9]|[1-9][0-9]|1\d\d|2[0-4]\d|25[0-4])$/
    return reg.test(value)
};

// 判断是否为IPv6地址,用于单个具有实际意义的IP地址
export function isIPv6(value) {
    const reg = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/
    return reg.test(value)
};

// 判断是否为IP地址，支持IPv4、IPv6
export function isIP(value){
    if(isIPv4(value)){
        return true;
    } else {
        return isIPv6(value);
    }
}

// 判断是否为IPv4网络地址，用于校验XXX.XXX.XXX.XXX/xx中的IP地址格式
export function isNetIPv4(value) {
    const reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
    return reg.test(value)
};

// 判断是否为Mac地址
export function isMac(value) {
    const reg = /^[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}$/i
    return reg.test(value)
};

// 判断是否为Netmask地址
export function isNetmask(value) {
    // 创建 Set
	const netmaskSet = new Set(["128.0.0.0","192.0.0.0","224.0.0.0","240.0.0.0","248.0.0.0","252.0.0.0","254.0.0.0",
    "255.0.0.0","255.128.0.0","255.192.0.0","255.224.0.0","255.240.0.0","255.248.0.0","255.252.0.0","255.254.0.0",
    "255.255.0.0","255.255.128.0","255.255.192.0","255.255.224.0","255.255.240.0","255.255.248.0","255.255.252.0",
    "255.255.254.0","255.255.255.0","255.255.255.128","255.255.255.192","255.255.255.224","255.255.255.240",
    "255.255.255.248","255.255.255.252","255.255.255.254","255.255.255.255"]);
    if (!netmaskSet.has(value)){
        return false;
    }
    return true;
};
